package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CircleRegion {
	static int[] createCircle( int radius, int centerX, int centerY ) {
		int[] points = new int[360 * 2];
		for ( int i = 0; i < 360; i++ ) {
			points[i * 2] = centerX + ( int ) ( radius * Math.cos( Math.toRadians( i ) ) );
			points[i * 2 + 1] = centerY + ( int ) ( radius * Math.sin( Math.toRadians( i ) ) );
		}
		return points;
	}

	/**
	 * @param args
	 */
	public static void main( String[] args ) {
		Display display = Display.getDefault();
		final Shell shell = new Shell( display, SWT.SHELL_TRIM );
		shell.open();

		GC gc = new GC( shell ); // 画笔
		Region region = new Region(); // Region
		region.add( createCircle( 200, 200, 200 ) );
		gc.setBackground( display.getSystemColor( SWT.COLOR_BLUE ) );
		gc.setClipping( region );
		gc.fillRectangle( new Rectangle( 0, 0, 1000, 1000 ) );

		while ( !shell.isDisposed() ) {
			if ( !display.readAndDispatch() ) display.sleep();
		}
		display.dispose();
	}
}
